package action.manage;

import hirondelle.date4j.DateTime;

import java.sql.Timestamp;
import java.util.List;

import model.app.AppFinance;

import core.action.BaseAction;
import service.manage.FinanceService;
import util.Time;

public class FinanceAction extends BaseAction{
	private FinanceService financeService;
	private AppFinance finance;
	private List<?> list;
	
	private String droyear;
	private String dromonth;
	
	private String flag;
	
	private String id;
	
	public String execute(){
		return "success";
	}

	public String list(){
		list=financeService.getFinanceList();
		super.successResultValue="financelist";
		return "success";
	}
	
	public String add(){
		flag="add";
		super.successResultValue="financeadd";
		return "success";
	}
	
	public String edit(){
		flag="edit";
		finance=financeService.getFinance(id);
		Timestamp financedate=finance.getFinancedate();
		DateTime a=new DateTime(Time.Timestamp2TimeString(financedate));
		droyear=String.valueOf(a.getYear());
		dromonth=String.valueOf(a.getMonth());
		super.successResultValue="financeadd";
		return "success";
	}
	
	public String save(){
		
		String yearmonth=droyear+"-"+dromonth;
		finance.setFinancedate(Time.String2Timestamp(yearmonth,"yyyy-M"));
		finance.setCreatetime(Time.CurrentTimestamp());
		financeService.save(finance);
		MessageJump("操作成功","../manage/financeAction!list");
		return "message";
	}
	
	public FinanceService getFinanceService() {
		return financeService;
	}

	public void setFinanceService(FinanceService financeService) {
		this.financeService = financeService;
	}

	public List<?> getList() {
		return list;
	}

	public void setList(List<?> list) {
		this.list = list;
	}

	public AppFinance getFinance() {
		return finance;
	}

	public void setFinance(AppFinance finance) {
		this.finance = finance;
	}

	public String getDroyear() {
		return droyear;
	}

	public void setDroyear(String droyear) {
		this.droyear = droyear;
	}

	public String getDromonth() {
		return dromonth;
	}

	public void setDromonth(String dromonth) {
		this.dromonth = dromonth;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getFlag() {
		return flag;
	}

	public void setFlag(String flag) {
		this.flag = flag;
	}
}
